package online.mjchow.fic.util;

import com.alibaba.fastjson.JSON;

import java.util.HashMap;

/**
 * Created by mjchow on 16-10-30.
 */
public class ApiResult extends HashMap<String, Object> {

    private static final String CODE = "code";
    private static final String MSG = "message";
    private static final String DATA = "data";
    private static final String PAGES = "pages";
    private static final String TOTAL = "total";
    private static final String PAGE_NUM = "pageNum";
    private static final String PAGE_SIZE = "pageSize";
    private static final String START_ROW = "startRow";
    private static final String END_ROW = "endRow";


    public ApiResult() {
        setCode(ApiStatus.SUCCESS);
    }

    public ApiResult(ApiStatus apiStatus) {
        setCode(apiStatus);
    }

    public void setCode(ApiStatus apiStatus) {
        super.put(CODE, apiStatus.getCode());
        super.put(MSG, apiStatus.getDesc());
    }

    public Integer getCode() {
        return (Integer)super.get(CODE);
    }

    public void setMessage(String msg) {
        super.put(MSG, msg);
    }

    public String getMessage() {
        return super.get(MSG).toString();
    }

    public void setData(Object data) {
        super.put(DATA, data);
    }

    public Object getData() {
        return super.get(DATA);
    }

    public void setPages(int pages) {
        super.put(PAGES, pages);
    }

    public void setTotal(long total) {
        super.put(TOTAL, total);
    }

    public void setPageNum(int pageNum) {
        super.put(PAGE_NUM, pageNum);
    }

    public void setPageSize(int pageSize) {
        super.put(PAGE_SIZE, pageSize);
    }

    public void setStartRow(int startRow) {
        super.put(START_ROW, startRow);
    }

    public void setEndRow(int endRow) {
        super.put(END_ROW, endRow);
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }

}
